<template>
  <div class="app-container">
    <el-form
      ref="dataForm"
      :model="dataForm"
      status-icon
      label-width="300px"
    >
      <el-tabs tab-position="left" >
        <el-tab-pane v-for="(list,key) in dataForm" :label="key">
          <el-form-item v-for="(config,index) in list" :label="config.desc+':'" >
            <!--<el-input v-model="dataForm[key][index].keyValue" style="width: 500px" />-->
            <el-input v-model="config.keyValue" style="width: 500px" />
          </el-form-item>
        </el-tab-pane>
      </el-tabs>
      <el-form-item>
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="update">保存</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>

<script>
import { list, update } from '@/api/config'

export default {
  name: 'ConfigWx',
  data() {
    return {
      dataForm: { }
    }
  },
  created() {
    this.init()
  },
  methods: {
    init: function() {
      list().then(response => {
        this.dataForm = response.data
      })
    },
    cancel() {
      this.init()
    },
    update() {
      update(this.dataForm)
        .then(response => {
          this.$notify.success({
            title: '成功',
            message: '配置成功'
          })
        })
        .catch(response => {
          this.$notify.error({
            title: '失败',
            message: response.msg
          })
        })
    }
  }
}
</script>
